#if !defined(__IAUTOOBJECT_H__)
#define __IAUTOOBJECT_H__

#define SAFE_DELETE(p)			{ if(p) { delete (p);     (p)=NULL; } }
#define SAFE_RELEASE(p)			{ if(p) { (p)->Release(); (p)=NULL; } }
#ifdef __Win32__
	#define SAFE_CLOSE_HANDLE(p)	{ if(p) { CloseHandle(p); (p)=NULL; } }
#endif

class  IAutoObject
{
public:
	IAutoObject() : m_iRef( 0 )	{}
	virtual ~IAutoObject(){};
	virtual void AddRef()
	{
		::InterlockedIncrement( &m_iRef );
	}
	virtual void Release()
	{ 
		if ( ::InterlockedDecrement( &m_iRef ) <= 0 )
			OnRefClose();
	}
protected:
	virtual void OnRefClose(){delete this;}
protected:
	LONG	m_iRef;
};


#endif //__IAUTOOBJECT_H__